# -*- coding: utf-8 -*-
import RPi.GPIO as GPIO
import time
import signal
import atexit
 
atexit.register(GPIO.cleanup)

servopin=4
GPIO.setmode(GPIO.BCM)
GPIO.setup(servopin,GPIO.OUT,initial=False)
p=GPIO.PWM(servopin,50)	
p.start(0)		
time.sleep(2)
state = "close"
def openDoor():
    global state
    if state == "close":
        for i in range(0,160,10):
            p.ChangeDutyCycle(2.5+10*i/180)			
            time.sleep(0.3)					
        state = "open"
def closeDoor():
    global state
    if state == "open":
        for i in range(160,0,-10):
            p.ChangeDutyCycle(2.5+10*i/180)
            time.sleep(0.3)
        state = "close"
        
